﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
//using EasyLib.DB.AbstractLayer;
//using NopSolutions.NopCommerce.Common.Utils;
using System.Collections;
using System.Web.Caching;
using Tour.BLL;
using Tour.DAL;
using System.Collections.Generic;

namespace VST.Controls
{
    public class BaseLCGMasterPage : MasterPage
    {
        static string keyResource = "Resource";
        public static BaseLCGPage CreateInstant()
        {
            return new BaseLCGPage();
        }
        public string GetLocaleResourceString(string resourceName)
        {
            if (HttpContext.Current.Cache[keyResource] == null)
            {
                CacheLocaleResourceString();
            }
            Hashtable ht = (Hashtable)HttpContext.Current.Cache[keyResource];
            string key = WorkingLanguage + "_" + resourceName;
            if (ht[key] != null)
                return ht[key].ToString();
            return "";
        }
        void CacheLocaleResourceString()
        {
            Hashtable ht = GetAllLocaleResourceString();
            Cache.Insert(keyResource, ht, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero, CacheItemPriority.Default, new CacheItemRemovedCallback(CachedItemRemoveCallBack));
        }
        private void CachedItemRemoveCallBack(string key, object value, CacheItemRemovedReason reason)
        {
            if (HttpContext.Current.Cache[keyResource] == null)
            {
                CacheLocaleResourceString();
            }
        }
        Hashtable GetAllLocaleResourceString()
        {
            Hashtable resource = new Hashtable();
            List<LocaleStringResourceEntity> ls = LocaleStringResourceManager.CreateInstant().SelectAll();
            for (int i = 0; i < ls.Count; i++)
            {
                string key = ls[i].LanguageID + "_" + ls[i].ResourceName;
                string value = ls[i].ResourceValue;
                resource.Add(key, value);
            }
            return resource;
        }

        
        public string getCreatedDate(string pubTime)
        {
            string strDate = "";
            DateTime artDate = DateTime.Parse(pubTime);
            if (WorkingLanguage == 1)
                strDate = String.Format("{0} {1}", artDate.ToString("dd/MM/yyyy"), artDate.ToString("hh:mm"));
            else
                strDate = String.Format("{0} {1}", artDate.ToString("MM/dd/yyyy"), artDate.ToString("hh:mm"));
            return strDate;
        }
        public static int WorkingLanguage
        {
            get
            {
                if (CommonHelper.GetCookieInt("VST.Language") > 0)
                    return CommonHelper.GetCookieInt("VST.Language");
                else
                    return 1;
            }
        }
    }
}